package com.wao.cms.domain;

import com.wao.base.domain.BaseMultitenantAuditingEntity;
import io.swagger.annotations.ApiModel;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Objects;

/**
 * Page entity.
 *
 * @author Arthur.
 */
@ApiModel(description = "Page entity. @author Arthur.")
@Entity
@Table(name = "cms_page")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Page extends BaseMultitenantAuditingEntity {

    private static final long serialVersionUID = 1L;

    @Column(name = "name")
    private String name;

    @Lob
    @Column(name = "content")
    private String content;

    @Column(name = "url")
    private String url;

    @Size(max = 8)
    @Column(name = "lang_key", length = 8)
    private String langKey;

    @NotNull
    @Column(name = "enabled", nullable = false)
    private Boolean enabled;

    @Column(name = "display_order")
    private Integer displayOrder;

    @ManyToOne(optional = false)
    @NotNull
    private Website website;

    @ManyToOne
    private Template template;

    public String getName() {
        return name;
    }

    public Page name(String name) {
        this.name = name;
        return this;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public Page content(String content) {
        this.content = content;
        return this;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUrl() {
        return url;
    }

    public Page url(String url) {
        this.url = url;
        return this;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getLangKey() {
        return langKey;
    }

    public Page langKey(String langKey) {
        this.langKey = langKey;
        return this;
    }

    public void setLangKey(String langKey) {
        this.langKey = langKey;
    }

    public Boolean isEnabled() {
        return enabled;
    }

    public Page enabled(Boolean enabled) {
        this.enabled = enabled;
        return this;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Integer getDisplayOrder() {
        return displayOrder;
    }

    public Page displayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
        return this;
    }

    public void setDisplayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
    }

    public Website getWebsite() {
        return website;
    }

    public Page website(Website website) {
        this.website = website;
        return this;
    }

    public void setWebsite(Website website) {
        this.website = website;
    }

    public Template getTemplate() {
        return template;
    }

    public Page template(Template template) {
        this.template = template;
        return this;
    }

    public void setTemplate(Template template) {
        this.template = template;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Page page = (Page) o;
        if (page.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), page.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "Page{" +
            "id=" + getId() +
            ", name='" + getName() + "'" +
            ", content='" + getContent() + "'" +
            ", url='" + getUrl() + "'" +
            ", langKey='" + getLangKey() + "'" +
            ", enabled='" + isEnabled() + "'" +
            ", displayOrder='" + getDisplayOrder() + "'" +
            "}";
    }
}
